package com.shxy.api.bean.news;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.List;

/**
 * 新闻类别
 */
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "tb_catalog")
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
@SQLDelete(sql = "update tb_catalog set deleted = 1 where id = ?")
@Where(clause = "deleted = 0")
public class CatalogBean {
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @Column(length = 32)
    private String id;                  // 编号
    @Column(nullable = false)
    private String name;                // 名称
    @ManyToOne
    @JoinColumn(name = "parent_id")
    private CatalogBean parent;         // 父节点
    @Column(name = "deleted")
    private int deleted = 0;            // 删除标志

    @Transient
    List<CatalogBean> childrenList;     // 子节点列表
}
